<div class="p-head">
    <b class="c3">预算</b>
    <div class="r">
        <a href="/bbs/index/3/" class="ajax" title="意见反馈">意见反馈</a>
    </div>
    <div id="desc">
        记录你的消费预算。。。
    </div>
</div>
<div id="budget">
    <div class="tabs_t tabs_n">
        <ul class="ajax">
            <li class="current"><a href="/budget/index/">我的预算</a></li>                        
        </ul>
        <span class="r clear">
            <a href="/budget/add/" title="建立预算" close="true" callback="budget_callback" class="btn btn_g_s dialog"><span><b class="icon icon-edit"></b><em>建立预算</em></span></a>
        </span>
    </div>
    <div id="budget_inner">
        <?php for ($i = (int) date("m"); $i >= 1; $i--) { ?>
            <?php
            $month = $i;
            $w = isset($real['expense'][$month]) ? $real['expense'][$month]['all'] : 0;
            $b = isset($budget['expense'][$month]) ? $budget['expense'][$month]['all'] : 0;
            $max = 660;
            $ratio = $b > 0 ? ($w / $b) * 100 : 0;
            $ratio = $ratio > 100 ? 100 : $ratio;
            $ratio = $b == 0 && $w > 0 ? 50 : $ratio;
            $left = ($ratio / 100) * $max;
            ?>
            <dl class="clear">
                <dt><?= $i; ?>月</dt>
                <dd>
                    <div class="lp-loading" title="实际:<?= isset($real['expense'][$month]['all']) ? $real['expense'][$month]['all'] : 0 ?>&#13;预算:<?= isset($budget['expense'][$month]['all']) ? $budget['expense'][$month]['all'] : 0 ?>&#13;点击展开分类预算详情">
                        <label class="llabel">0</label>
                        <?php if ($w > $max && $b > 0) { ?>
                            <label style="right:0px;" class="c1label"><?= (int) $w . "/" . $b ?></label>
                        <?php } else { ?>
                            <label style="left:<?= $left ?>px;" class="c1label"><?= $w > 0 ? (int) $w : '' ?></label>
                        <?php } ?>
                        <label class="rlabel"></label>
                        <span class="left"></span>
                        <span class="right"></span>
                        <ul class="<?= $ratio > 90 ? 'orange' : '' ?>">
                            <li class="l"></li>
                            <li style="width:0px;" rel="<?= $left ?>" class="load" id="load"></li>
                            <li class="r"></li>
                        </ul>
                    </div>
                    <div class="budget_inner_i ajax clear <?= date("m") == $i ? '' : 'hidden' ?>">
                        <?php foreach ($out as $k => $v) { ?>
                            <?php
                            $t = 0;
                            if (isset($real['expense'][$month][$v['id']])) {
                                if (isset($budget['expense'][$month][$v['id']])) {
                                    $t = $budget['expense'][$month][$v['id']] > 0 ? ceil($real['expense'][$month][$v['id']] / $budget['expense'][$month][$v['id']] * 100) : 100;
                                } else {
                                    $t = $real['expense'][$month][$v['id']] > 0 ? 100 : 0;
                                }
                            }
                            ?>
                            <a href="/bill/?category_id=<?= $v['id'] ?>&startdate=<?= $year ?>-<?= $i ?>-01&enddate=<?= $year ?>-<?= $i ?>-31" title="实际:<?= isset($real['expense'][$month][$v['id']]) ? $real['expense'][$month][$v['id']] : 0 ?>&#13;预算:<?= isset($budget['expense'][$month][$v['id']]) ? $budget['expense'][$month][$v['id']] : 0 ?>&#13;点击查看消费详情">
                                <div class="chart">
                                    <div class="percentage" data-percent="<?= $t ?>" data-color="<?= $t >= 85 ? "#F0615A" : "#8DCF35" ?>">
                                        <div class="label"><?= cutstr($v['name'],10) ?></div>
                                        <div class="percent"><?= $t ?> %</div>
                                    </div>
                                </div>
                            </a>
                        <?php } ?>
                    </div>
                </dd>
            </dl>
        <?php } ?>
    </div>
</div>
<script type="text/javascript">
    $(function() {
        KS.common.load('budget.index');
        KS.budget.show();
    });
</script>